package vn.edu.hcmut.cse.ai.infrastructure;

public class Node {

    // The state in the state space to which the node corresponds
    private Object state;

    // The node in the seach tree that generated this node
    private Node parent;

    // The action that was applied to the parent to generate the node
    private Action action;

    // The cost, traditionally denoted by g(n), of the path from the initial state
    // to the node, as indicated by the parent pointers
    double pathCost;
    
    // The heuristic point. Bigger is better
    double heuristicPoint;

    public Node(Object state, Node parent, Action action) {
        this.state = state;
        this.parent = parent;
        this.action = action;
        this.pathCost = 0.0;
        this.heuristicPoint = Double.NEGATIVE_INFINITY;
    }

    public Node(Object state, Node parent, Action action, double stepCost) {
        this(state, parent, action);
        this.pathCost = this.parent.getPathCost() + stepCost;
        this.heuristicPoint = Double.NEGATIVE_INFINITY;
    }

    public Object getState() {
        return state;
    }

    public void setState(Object state) {
        this.state = state;
    }

    public Node getParent() {
        return parent;
    }

    public void setParent(Node parent) {
        this.parent = parent;
    }

    public Action getAction() {
        return action;
    }

    public void setAction(Action action) {
        this.action = action;
    }

    public double getPathCost() {
        return pathCost;
    }

    public void setPathCost(double pathCost) {
        this.pathCost = pathCost;
    }

    public double getHeuristicPoint() {
        return heuristicPoint;
    }

    public void setHeuristicPoint(double distance) {
        this.heuristicPoint = distance;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 53 * hash + this.state.hashCode();
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Node other = (Node) obj;

        return this.state.equals(other.getState());
    }

    @Override
    public String toString() {
        return "Node{" + "state=" + state + '}';
    }
    
    

}
